package com.dxf.http.demo;

import com.alibaba.fastjson.JSONObject;
import com.dxf.http.ShowDocAddDoc;
import okhttp3.*;

import java.io.IOException;

public class test {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();
        ShowDocAddDoc.ShowDocPageModel model = ShowDocAddDoc.GetModel("11111");

        String s = JSONObject.toJSONString(model);
        String result = post(client, ShowDocAddDoc.addPageUrl, s);
        System.out.println(result);
    }

    public static String get(OkHttpClient client, String url) throws IOException {

        Request request = new Request.Builder().url("http:\\www.baidu.com").build();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }

    public static String post(OkHttpClient client, String url, String json) throws IOException {
        MediaType JSON = MediaType.get("application/json; charset=utf-8");

        RequestBody body = RequestBody.create(JSON, json);
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        Response response = client.newCall(request).execute();
        return response.body().string();
    }

}
